import Base from "./base";
const tableName = `admin_user`;
export default class extends Base {
  static get _REST() {
    return false;
  }
  async listAction() {
    const page = this.get("page") || 1;
    const size = this.get("size") || 10;
    const name = this.get("name") || "";

    const where = {};

    const $Service = think.service("aiImgService");
    const data = await $Service.list({
      where,
      page,
      size,
    });
    this.success(data);
  }
  async selectAction() {
    const taskId = this.get("taskId");
    if (!taskId) {
      return this.fail("请填写taskId");
    }
    const $Service = think.service("baidu", "api");

    const data = await $Service.selectTask(taskId);
    this.success(data);
  }
  async myAction() {
    const page = this.get("page") || 1;
    const size = this.get("size") || 10;
    const name = this.get("name") || "";
    const member_id = this.ctx.state.userId;
    const where = {
      member_id,
    };

    const $Service = think.service("aiImgService");
    const data = await $Service.list({
      where,
      page,
      size,
    });
    this.success(data);
  }
  async addAction() {
    const member_id = this.ctx.state.userId;
    const user_img = this.post("user_img");
    if (user_img && !/^http/.test(user_img)) {
      return this.fail("图片必须是连接");
    }

    const data = {
      out_img: this.post("out_img") || "",
      text: this.post("text") || "",
      style: this.post("style") || "",
      ratio: this.post("ratio") || "",
      status: 0,
      taskId: "",
      type: this.post("type") || "",
      remarks: this.post("remarks") || "",
      is_delete: 0,
      member_id,
    };
    console.log(user_img);

    console.log("到了这里");
    console.log(data);

    const $Service = think.service("aiImgService");
    const rData = await $Service.add(data);
    if (think.isEmpty(rData)) {
      return this.fail("提交失败");
    }
    return;
    if (data.type == 1 || data.type == 2) {
      rData.status = 1;
      const $baiduSerice = think.service("baidu", "api");
      $baiduSerice.addTask(rData);
    }
    return this.success(rData);
  }
}
